//
//  GameComTableViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/3/5.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "GameComTableViewCell.h"
#import "GameXiangQingPingLun.h"
#import "UIButton+WebCache.h"
@implementation GameComTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews{
    
    self.headerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_headerButton];
    
    
    self.nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
    [_nameLabel release];
    
    
    self.textLabel1 = [[UILabel alloc] init];
    [self.contentView addSubview:_textLabel1];
    [_textLabel1 release];
    
    self.timeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_timeLabel];
    [_timeLabel release];
    
    
}

-(void)setModel:(GameXiangQingPingLun *)model{
    
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    NSDictionary *dic = _model.user;
    
    [_headerButton sd_setBackgroundImageWithURL:[NSURL URLWithString:dic[@"avatar_m"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:PLACE_HLODER] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    
    NSString *str = [NSString stringWithFormat:@"%@:", dic[@"name"]];
    _nameLabel.text = str;
    
    _textLabel1.text = _model.comment;
    
   
    
    //设置时间的显示格式
    NSString *timeStr = @"2016-01-26 17:40:50";
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    
    
    NSTimeZone *timeZone = [NSTimeZone localTimeZone];
  
    
    [formatter setTimeZone:timeZone];
    
    NSDate *date = [formatter dateFromString:timeStr];
    NSLog(@"%@", date);
    NSDate *dateMow = [NSDate date];
    NSString *nowTimeStr = [formatter stringFromDate:dateMow];
    NSLog( @"%@", nowTimeStr);
    
    NSInteger time = [_model.date_added integerValue];
    
    NSDate *confromTimeSp = [NSDate dateWithTimeIntervalSince1970:time];
    
    NSLog(@"123232%@", confromTimeSp);
    
    NSString *conFromTimespStr = [formatter stringFromDate:confromTimeSp];
    
    _timeLabel.text = conFromTimespStr;
    
 
    
   
    
    
}

- (void)layoutSubviews{
    
    _headerButton.frame = CGRectMake(15, 15, 50, 50);
    
    _headerButton.layer.cornerRadius = 25;
    _headerButton.layer.masksToBounds = YES;
    _nameLabel.frame = CGRectMake(85, 15, 50, 20);
   
    _nameLabel.font = [UIFont systemFontOfSize:14];
    _nameLabel.textColor = [UIColor cyanColor];
    
    _textLabel1.frame = CGRectMake(135, 15, 200, 20);
    _textLabel1.textColor = [UIColor grayColor];
    _textLabel1.font = [UIFont systemFontOfSize:13];
    
    _timeLabel.frame=  CGRectMake(85, 40, 230, 20);
    _timeLabel.font = [UIFont systemFontOfSize:13];
    _timeLabel.textColor = [UIColor grayColor];
    
    
}



- (void)dealloc{
    [_headerButton release];
    [_nameLabel release];
    [_timeLabel release];
    [_textLabel1 release];
    [_model release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
